package com.enbatis.mybatisplugs.controller;
import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.commons.utils.*;
import com.enbatis.mybatisplugs.entity.vo.SysRoleVO;
import com.enbatis.mybatisplugs.plugin.Pages;
import com.enbatis.mybatisplugs.service.SysRoleService;
import com.enbatis.mybatisplugs.base.BaseController;
import com.github.pagehelper.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jcifs.smb.SmbFile;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.enbatis.mybatisplugs.entity.SysRole;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("v1/sys_role")
public class SysRoleController extends BaseController {

@Autowired
private SysRoleService sysRoleService;


    @PostMapping("/add")
    public ResultReturn<SysRole> add(@RequestBody SysRole sysRole){
        return  success(sysRoleService.insert(sysRole));
    }


    @DeleteMapping("/delete")
    public ResultReturn<Integer> delete(@RequestParam("id") Long id){
        return success(sysRoleService.deleteById(id));
    }


    @PutMapping("/{id}")
    public  ResultReturn<Integer> update(@PathVariable("id") Long id,@RequestBody SysRole sysRole){
        sysRole.setId(id);
        return success(sysRoleService.updateById(sysRole));
    }


    @GetMapping("/{id}")
    public ResultReturn<SysRole> get(@PathVariable("id") Long id) {
        return success(sysRoleService.getById(id));
    }


    @GetMapping("/list")
    public ResultReturn<List<SysRole>> getList(SysRole sysRole){
        return success(sysRoleService.list(new Wrapper<>(sysRole)));
    }


    @GetMapping("/list_parent")
    public ResultReturn<List<SysRole>> getListParent(){
        return success(sysRoleService.list(new Wrapper<>(new SysRole()).eq("pid",0)));
    }


    @ApiOperation(value = "分页列表", notes = "分页查询数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "请求数据的页码", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "rows", value = "每页条数", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "sidx", value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sord", value = "排序方式", paramType = "query", dataType = "String"),
    })
    @PostMapping("/page")
    public ResultReturn<Pages<SysRole>> getPage(SysRole user){
        Page<SysRole> page= getPage();
        return success(sysRoleService.page(page,new Wrapper<>(user)));
    }



    @ApiOperation(value = "分页列表", notes = "分页查询数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "请求数据的页码", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "rows", value = "每页条数", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "sidx", value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sord", value = "排序方式", paramType = "query", dataType = "String"),
    })
    @PostMapping("/page_vo")
    public ResultReturn<Pages<SysRoleVO>> getPage(SysRoleVO user){
        Page<SysRoleVO> page= getPage();
        return success(sysRoleService.pageVO(page,user));
    }


    @ApiOperation(value = "分页列表", notes = "分页查询数据列表")
    @GetMapping("/get_files")
    public ResultReturn<String>  getFiles(){
        String url="smb://lzjc:123456@192.168.77.29/SampleResult/";
        try {
            SmbFile[] files= ShareDownUtil.getShareFiles(url);
            if (ArrayUtils.isEmpty(files)){
                return success("共享文件为空");
            }else{

                 System.out.println("获取到文件");
                StringBuffer sb=new StringBuffer();

                System.out.println("开始解析");
                for (SmbFile file:files) {
                    System.out.println("开始解析1---");
                    Map<String, DataCollectItem> dataMap=   ReadSpecXmlByDom.getParseSpectroData(file.getInputStream());
                    for (Map.Entry<String, DataCollectItem> entry: dataMap.entrySet()) {
                        sb.append(entry.getKey());
                    }
                }

                return  success(sb.toString());

            }
        }catch (Exception e){
            e.printStackTrace();
            return success(e.getMessage());

        }

    }



}
